<template>
  <div class="msxq" ref="msxq1" @scroll="scro">
    <div class="title">
      <span @click="$router.go(-1)">◀</span>
      <span>名师详情</span>
      <span style="font-size: 14px" @click="$router.push('/qbls')"
        >全部老师</span
      >
    </div>
    <div class="center">
      <li class="ll">
        <img class="ii" :src="obj.list.avatar" alt="" />
        <span>{{ obj.list.name }}</span>
      </li>
    </div>
    <div class="js">
      <span>{{ obj.list.teacher_info }}</span>
    </div>
    <div class="zj">
      <span class="kk">主讲课程({{ obj.total }})</span>
    </div>

    <!--内容...-->
    <div class="scroll" ref="scroll" @scroll="gdhz">
      <div class="spkp" v-for="(item, index) in obj.kcs" @click="txq(item)">
        <span class="q1">{{ item.course_classify_title }}</span>
        <p class="q2">{{ item.title }}</p>
        <span class="q3">{{ filtt(item.start_time) }}</span>
        <ul>
          <li class="q4" v-for="(item1, index1) in item.teacher">
            <img class="qi" :src="item1.avatar" alt="" /><span>{{
              item1.teacher_name
            }}</span>
          </li>
        </ul>
        <div class="q5">
          <span>{{ item.sales_num }}人已报名</span>
          <span
            style="font-size: 18px"
            :class="item.price == 0 ? 'ls' : 'hs'"
            >{{ filte(item.price) }}</span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref, toRefs } from "vue";
import { useRoute, useRouter } from "vue-router";
import { getmsxq, allkc } from "../http/api.js";
// import MescrollVue from "mescroll.js/mescroll.vue";
const router = useRouter();
const scroll = ref(null);
const obj = reactive({
  list: [],
  kcs: [],
  page: 1,
  total: "",
});
console.log(scroll);
// 点击去详情
const txq = (i) => {
  console.log(i);
  router.push({ path: "/xq", query: { id: i.id } });
};
// 滚动盒子
const gdhz = (e) => {
  let offsetHeight = scroll.value.offsetHeight;
  let scrollTop = scroll.value.scrollTop;
  let scrollHeight = scroll.value.scrollHeight;
  if (offsetHeight + scrollTop >= scrollHeight) {
    obj.page++;
    // console.log(11);
    console.log(obj.kcs);
    getkc();
  }
};
function filte(i) {
  if (i == 0) {
    return "免费";
  } else {
    return i;
  }
}
function filtt(timestamp) {
  var date = new Date(timestamp * 1000);
  var Y = date.getFullYear() + "-";
  var M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  var D =
    date.getDate() < 10 ? "0" + date.getDate() + " " : date.getDate() + " ";

  return Y + M + D;
}
const route = useRoute();
// 获取所有课程
const getkc = async () => {
  const res = await allkc(route.query.id, obj.page);
  obj.kcs = [...obj.kcs, ...res.data.data];
  obj.total = res.data.total_count;
  console.log(obj.kcs);
};
const getxq = async () => {
  const res = await getmsxq(route.query.id);
  console.log(res);
  obj.list = res.data.data;
};
getxq();
getkc();
</script>
<style lang="scss" scoped>
.scroll {
  overflow: auto !important;
  height: calc(100% - 620px);
}
.q5 {
  padding: 15px 0;
  display: flex;
  justify-content: space-between;
}
.ls {
  color: green;
}
.hs {
  color: red;
}
.qi {
  width: 70px;
  height: 70px;
  border-radius: 50%;
}
ul {
  padding: 15px 0;
  display: flex;
  li {
    display: flex;
    align-items: center;
    margin-right: 10px;
    img {
      margin-right: 5px;
    }
  }
}
.q3 {
  margin-left: 15px;
  display: inline-block;
  padding: 8px 8px;
  background: #f5f6f8;
  border-radius: 15px;
}
.q2 {
  padding: 15px 0 5px 0;
  font-size: 26px;
}
.q1 {
  background: #f15a24;
  padding: 5px 15px;
  color: #fff;
}
.spkp {
  padding: 15px;
}
.kk {
  border-bottom: 3px #f15a24 solid;
  display: inline-block;
  box-sizing: border-box;
  padding: 15px;
}
.zj {
  padding: 15px;
}
* {
  list-style: none;
}
.js {
  width: 90%;
  margin: 0 auto;
  transform: translateY(-50%);
  background: #fff;
  padding: 15px;
  border-radius: 10px;
}
.ll {
  height: 100px;
  text-align: center;
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
  span {
    margin-top: 15px;
  }
}
.ii {
  width: 80px;
  height: 80px;
  border-radius: 50%;
}
.center {
  height: 400px;
  background-color: #51bdfd;
  border-top: 1px solid #51bdfd;
  position: relative;
  margin-top: 45px;
}
.msxq {
  width: 100%;
  height: 100vh;
  overflow: auto;
  //   height: 100% !important;
}
.title {
  display: flex;
  justify-content: space-between;
  position: fixed;
  left: 0;
  right: 0;
  box-sizing: border-box;
  top: 0;
  background: #fff;
  width: 100%;
  padding: 15px;
  z-index: 1000;
  span {
    font-size: 35px;
  }
}
* {
  margin: 0;
  padding: 0;
}
</style>
